package xyz.labmem.result

import cn.hutool.http.ContentType
import cn.hutool.http.server.HttpServerResponse
import com.alibaba.fastjson.JSON
import com.alibaba.fastjson.JSONObject
import com.alibaba.fastjson.annotation.JSONField
import java.time.LocalDateTime

/**
 * @Author lty
 * @Date 2021/10/11 11:02
 */
open class ResultVo<T>(
    //状态码 0:处理成功；-1:处理失败；-2:表单验证失败；-3:登录失效"
    var code: Int?,
    //提示信息
    var message: String?,
    //返回数据
    var data: T?
) : ResultUtil(), SendRes {
    constructor() : this(null, null, null) {}

    //返回时间
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    var timestamp: LocalDateTime = LocalDateTime.now()

    //发送
    override fun sendRes(res: HttpServerResponse) {
        val s = JSON.toJSONString(this)
        res.write(s, ContentType.JSON.toString())
    }


}